package mofei.concurrent.task;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 令人意外的是，ReentrantLock产生死锁后，线程进入了waiting状态
 * 具体原因需要查询，这应该就是reentrantLock比synchronized快的原因
 * todo 查看原因
 * @author mofei@staff.weibo.com
 * @date 2019/2/22 2:23 PM
 */
public class BlockedTask3 implements Runnable {

    public static ReentrantLock lock1=new ReentrantLock();
    public static ReentrantLock lock2=new ReentrantLock();



    @Override
    public void run() {
        try{
            lock1.lock();
            System.out.println("获取lock1锁，进入休眠");
            Thread.sleep(1000*5);
            System.out.println("lock1苏醒，开始竞争lock2");
            lock2.lock();
            System.out.println("已获取lock2");
        }catch (Exception e){
            e.printStackTrace();
        } finally{
            lock1.unlock();
            lock2.unlock();
        }

    }
}
